package controller;


import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import pojo.Goods;
import pojo.Orders;
import service.GoodServiceImpl;
import service.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
public class OrderController {

    @Autowired
    @Qualifier("OrderServiceImpl")
    private OrderServiceImpl orderService;


    @ResponseBody
    @RequestMapping(value = "/allOrders",produces="text/html;charset=utf-8")
    public String allOrders( HttpServletResponse response, HttpServletRequest request) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/json; charset=utf-8");    // 设置response的编码及格式
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Cache-Control","no-cache");
        List<Orders> list = orderService.queryAllBook();
        String resJSON = JSON.toJSONString(list);     // 转换为json
        return resJSON;
    }

}
